subject to covariant.
// Declare the Find
Find
// Declare the Find
Find
Iv. Coordination and inverter in generic interfaces:
The covariant inversion in the generic interface is very similar to that in the generic delegate, but the angle brackets of the generic definition are changed to the interface definition.
1. Inverter in generic Interfaces
The following interface definition:
Public interface IFeedable
{
Void Feed (T t );
}
An in keyword exists before the interface generic
generic InterfacesThe following interface definition:Copy codeThe Code is as follows:Public interface IFinder {T Find ();}The out keyword is used before the generic T of a generic interface to indicate that this interface may be subject to covariant. the following generic interface implementation classCopy codeThe Code is as follows:Public class Finder {Public T Find (){Return new T ();}}// Use covariant. The generic type of
the FeedImp 2. covariant in generic InterfacesThe following interface definition:Copy codeThe Code is as follows: public interface IFinder {T Find ();}
The out keyword is used before the generic T of a generic interface to indicate that this interface may be subject to covariant. the following generic interface implementation classCopy codeThe Code is as follows: public class Finder {Public T Find (){Return new T ();}}// Use covariant. The generic ty
Return False ; 25 } 26 } 27 }
Start searching here: 1 Ipoint temppoint = New Ipoint ( 1 , 2 ); 2 Finder ifinder = New Finder (temppoint ); 3 Ipoint findres = Closedlist. Find ( New Predicate Ipoint > (Ifinder. findcurrentpoint ));
OK. Here we find the ipoint object of Y = 1, x = 2.Sort ()We need to first create a class that inherits from icomparer
Public
interface inversion: ifeedable Dog ; feeddog = new feedimp Animal ; (); The code above // assigns the feedimp 2. Covariance in generic interfacesC # codeCopy//Definition of the interface:Public InterfaceIfinderOutT> {T Find ();} The // generic interface's generic t was preceded by an out keyword to indicate that this interface is likely to be covariant; The following generic interface implementation class public class Finder T ; :
generic type is Feedimp
Copy Code code as follows:
public class Feedimp{
public void Feed (T-t) {
Console.WriteLine ("Feed Animal");
}
}
Look at an example of using interface contravariance:
Copy Code code as follows:
ifeedable
The code above assigns the feedimp
2. Covariance in a generic interfaceThe definition of the following interface:
Copy Code code as follows:
public interface Ifinder
Finderwhere T:new(){ public T Find(){ return new T(); } } With covariance, the generic type of Ifinder is animal, but because of the Out keyword, I can assign the finder to it.IFinderAnimal> finder = new FinderDog>();The concept of covariance and contravariance is not easy to understand, and can be understood through actual code thinking. Is it really useful to wrap things around like this? The answer is yes, the code can be reused better through
. this article mainly discusses the weighted Sorting Algorithm for Word Frequency locations.
1. 2 weighted Sorting Algorithm for Word Frequency locations
Word Frequency location weighted sorting algorithm is a basic algorithm in web page sorting. The idea of Lucene, a famous open-source full-text search package, is to use the weighted Sorting Algorithm for Word Frequency location, lucene has been widely used in search engines. A large number of search engines, such as the German website search s
Contact Us
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.